const path = require("path");
import { defineConfig, loadEnv } from "vite";
import vue from "@vitejs/plugin-vue";

export default (({ mode }) => {
	const config = loadEnv(mode, './')
	return defineConfig({
		resolve: {
			alias: {
				"@": path.resolve(__dirname, "./src"),
			},
		},
		plugins: [vue()],
		outDir: "dist",
		base: "./",
		server: {
			host: "0.0.0.0",
			port: "6060",
			open: false, // 浏览器自动打开
			https: false, // 是否开启 https
			ssr: false, // 服务端渲染
			proxy: {
				"/apis": {
					target: config.VITE_REQUEST_URL, // 后端服务实际地址
					changeOrigin: false,
					rewrite: path => path.replace(/^\/apis/, "")
				}
			},
		},
		module: {
			rules: [
				{
					test: /\.css$/,
					use: [
						"vue-style-loader",
						{
							loader: "css-lader",
							options: {
								modules: true,
								localIdentName: "[local]_[hash:base:8]"
							}
						}
					]
				}
			]
		},
	})
})